package models

import (
	"github.com/astaxie/beego/orm"
)

type Banner struct {
	Id          int
	Image       string `orm:"size(255)" description:"图片"`
	Description string `orm:"size(255)" description:"介绍"`
	Linker      string `orm:"size(255)" description:"链接地址"`
	Sort        int    `description:"排序越大越靠前"`
}

func init() {
	orm.RegisterModel(new(Banner))
}

func AddOne(image string, description string, linker string, sort int) (error, *Banner) {
	o := orm.NewOrm()
	banner := &Banner{
		Image:       image,
		Description: description,
		Linker:      linker,
		Sort:        sort,
	}
	_, error := o.Insert(banner)
	return error, banner
}

func UpdateOne(banner *Banner) (error, *Banner) {

	o := orm.NewOrm()
	
	_, error := o.Update(banner)
	return error, banner
}

func (self *Banner) Delete() error {
	o := orm.NewOrm()
	_, error := o.Delete(self)
	return error
}
